/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { Component } from 'react';
import { connect } from 'dva';
import PageHeaderLayout from '@/layouts/PageHeaderLayout';
import StandardTab from '@/components/StandardTab';
import OrderSource from './components/OrderSource';
import OperatorSetting from './components/OperatorSetting';
import ChargeRecords from './components/ChargeRecords';
import styles from '../commen.less';

@connect(({ setting }) => ({ ...setting }))
class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      activeKey: 'courier',
      subActiveKey: 'list',
    };
  }

  onChange = (activeKey, subActiveKey = 'list') => {
    const { dispatch } = this.props;
    this.setState({
      activeKey,
      subActiveKey,
    });
    dispatch({
      type: 'setter/save',
      payload: {
        sourceType: activeKey,
      },
    });
  };

  render() {
    const {
      options: { key },
    } = this.props;
    const { activeKey, subActiveKey } = this.state;
    const isZyAccount = key === 'post'; // 是否是中邮账号

    const panes = [
      {
        tab: '业务员单号源设置',
        key: 'operator',
        component: <OperatorSetting sourceType="operator" changeActiveKey={this.onChange} />,
      },
      {
        tab: '单号源',
        key: 'sources',
        component: <OrderSource activeKey={subActiveKey} />,
      },
    ];
    if (!isZyAccount) {
      panes.splice(
        1,
        0,
        {
          tab: '微商单号源设置',
          key: 'derivative',
          component: <OperatorSetting sourceType="derivative" changeActiveKey={this.onChange} />,
        },
        {
          tab: '下属驿站单号源设置',
          key: 'yz',
          component: <OperatorSetting sourceType="yz" changeActiveKey={this.onChange} />,
        },
      );
    }

    if (key == 'yz') {
      panes.push({
        tab: '单号充值记录',
        key: 'records',
        component: <ChargeRecords sourceType="yz" changeActiveKey={this.onChange} />,
      });
    }

    return (
      <PageHeaderLayout title="单号源设置">
        <div className={styles.main}>
          <StandardTab activeKey={activeKey} onChange={this.onChange} panes={panes} name="setter" />
        </div>
      </PageHeaderLayout>
    );
  }
}

export default Index;
